 local UIRegister=require("UIRegister")
 local m_UI_Register=UIRegister:Instance()
 local UIManager={
}

local UserContent={
    m_User_Id,
    m_User_Name,
    m_Head_Photo_Id,
    m_Content,
    m_Time,
    m_Content_Current_index
} 

local MyRoom={
    m_Room_Name,
    m_Room_Id,
    m_Room_Gameobject,
    m_Room_Current_Index
}

function UIManager:New()
    o={}
    setmetatable(o,self)
    self.__index=self
    return o
end

function UIManager:Instance()
    if self.instance==nil then
      self.instance=self:New()
    end
    return self.instance
end

local this=UIManager:Instance();

function UserContent:New(user_id,user_name,head_photo_id,content,time,index)
    o={}
    setmetatable(o,self)
    self.__index=self
    self.m_User_Id=user_id
    self.m_User_Name=user_name
    self.m_Head_Photo_Id=head_photo_id
    self.m_Content=content
    self.m_Time=time
    self.m_Content_Current_index=index;
    return o
end

function MyRoom:New(room_name,room_id,index)
    o={}
    setmetatable(o,self)
    self.__index=self
    self.m_Room_Name=room_name
    self.m_Room_Id=room_id
    self.m_Room_Current_Index=index
    return o
end


UIManager.m_Tab_UserContent={}

UIManager.m_Tab_MyroomAndContent={}


function UIManager:Start()
    CS.ClintSocket.Instance.m_Register = UIManager.Register + CS.ClintSocket.Instance.m_Register 
    CS.ClintSocket.Instance.m_Register_fail = UIManager.RegisterFail + CS.ClintSocket.Instance.m_Register_fail 
    CS.ClintSocket.Instance.m_Join_Room_Fail=UIManager.JoinRoomFail + CS.ClintSocket.Instance.m_Join_Room_Fail
    CS.ClintSocket.Instance.m_Save_And_Init_Room=UIManager.SaveAndInitRoom + CS.ClintSocket.Instance.m_Save_And_Init_Room
    CS.ClintSocket.Instance.m_Sreach_Room_List=UIManager.SreachRoomList + CS.ClintSocket.Instance.m_Sreach_Room_List
    CS.ClintSocket.Instance.m_Quit_Room=UIManager.QuitRoom + CS.ClintSocket.Instance.m_Quit_Room
    CS.ClintSocket.Instance.m_Quit_Room_Fail=UIManager.QuitRoomFail + CS.ClintSocket.Instance.m_Quit_Room_Fail
    CS.ClintSocket.Instance.m_Create_Room=UIManager.CreateRoom + CS.ClintSocket.Instance.m_Create_Room 
    CS.ClintSocket.Instance.m_Create_Room_Fail=UIManager.CreateRoomFail + CS.ClintSocket.Instance.m_Create_Room_Fail
    CS.ClintSocket.Instance.m_Get_Message_By_Room=UIManager.GetMessageByRoom + CS.ClintSocket.Instance.m_Get_Message_By_Room
end

 UIManager.m_user={}
 UIManager.m_cur_room_index=0

function UIManager:Register(user_id)
    print("self",self);
    print("userid==",user_id);
    --保存用户id和头像id
    this.m_user["user_id"]=user_id
    print("登录成功了");
    --开启世界聊天室
end

function UIManager:SaveAndInitRoom(room_id,room_name)
    print("进入房间成功，保存和改变循环列表里面的内容房间");
    print(this.m_user["user_id"])
    --保存这个房间的类
    print("当前m_Tab_MyroomAndContent的长度为", #this.m_Tab_MyroomAndContent)
    --在房间列表里新增一个prefabs
    --如果当前长度为0则直接加进来，否则需要查询有无这个房间
    if #this.m_Tab_MyroomAndContent > 0 then
       
    else    
       local myroom= MyRoom:New(room_name,room_id,0)
       print(myroom)
       this.m_Tab_MyroomAndContent[myroom]={}
       this.m_Tab_MyroomAndContent.length=1
       print("改变后m_Tab_MyroomAndContent的长度为",this.m_Tab_MyroomAndContent["length"]);
       print(this.m_Tab_MyroomAndContent[myroom])
    end

    --改变当前房间index
    this.m_cur_room_index=room_id
   
    --循环列表渲染这个房间的对话内容（没有内容） 
end


function UIManager:ChangeThisRoom(room_id)
    print("进入了房间里");
    --改变当前房间index
    self.m_cur_room_index=room_id
    --把无线循环列表渲染成这一层对话内容
end


function UIManager:SreachRoomList(room_ids,room_names)
    print("搜索房间成功");
    print(room_ids);
    for k,v in pairs(room_ids) do
    print(k,v);
    end
    print(room_names);
    for k,v in pairs(room_names) do
        print(k,v);
    end
end

function UIManager:QuitRoom(room_id)
    print("退出房间成功");
    
    --退出房间API
end


function UIManager:CreateRoom(room_id,room_name)
    --创建一个私人房间
    --table保存
   self:InitPrivateChatUI()
   print("创建房间成功");
end

function UIManager:GetMessageByRoom(user_id,user_name,head_id,content,room_id)
    print("得到信息成功");
 
    --保存到table里
    
    --查看是否在同一个对话层，如果在就调用增加对话接口
  
end


function UIManager:RegisterFail()
    print("登录失败了");
end

function UIManager:JoinRoomFail(error)
    print("加入房间失败了");
end

function UIManager:CreateRoomFail(error)
    print("创建房间失败");
end

function UIManager:QuitRoomFail(error)
    print("退出房间失败")
end


function UIManager:InitRegisterUI()
    --直接开启登录界面
      m_UI_Register:InitPrefabs()
      print("执行InitRegisterUI");
end

function UIManager:InitWorldChatUI()
    --渲染内容，或者直接开启
    print("执行InitWorldChatUI");
end

function UIManager:InitPrivateChatUI()
    --添加一个prefabs在房间列表里，进入这个房间
    print("执行InitPrivateChatUI");
end

return UIManager